<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力中小企业发展 
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德代驾系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
+----------------------------------------------------------------------
| 组件-选择司机数量弹窗 开发者: 麦沃德科技-半夏
+---------------------------------------------------------------------- -->

<template>
	<view class="component-modal-drivers-number" @click.stop>
		<uni-popup ref="popupModal" type="bottom" :safe-area="false" @change="onChange">
			<view class="popup-box" :style="{'--theme-color': themeColor}">
				<view class="popup-header">
					<view class="title">请选择司机数量</view>
					<image class="close" src="/static/close.png" mode="aspectFit" @click="onClose"></image>
				</view>
				<view class="popup-content flex-column">
					<view class="content-tips">请根据自身情况进行选择</view>
					<view class="content-list flex flex-wrap">
						<view class="list-item" :class="{active: selectNumber == 1}" @click="handleChange(1)">
							<view class="item-background"></view>
							<text class="item-text">1名</text>
						</view>
						<view class="list-item" :class="{active: selectNumber == 2}" @click="handleChange(2)">
							<view class="item-background"></view>
							<text class="item-text">2名</text>
						</view>
						<view class="list-item" :class="{active: selectNumber == 3}" @click="handleChange(3)">
							<view class="item-background"></view>
							<text class="item-text">3名</text>
						</view>
					</view>
				</view>
				<view class="popup-btn">
					<view class="btn confirm" @click="onConfirm">确认呼叫{{selectNumber}}名司机</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		name: "componentModalDriversNumber",
		data() {
			return {
				// 已选司机数量
				selectNumber: 1,
			};
		},
		computed: {
			...mapState({
				themeColor: state => state.app.themeColor,
			})
		},
		methods: {
			// 打开模态框
			open(value) {
				this.selectNumber = value
				this.$refs.popupModal.open()
			},
			// 关闭弹窗
			onClose() {
				this.$refs.popupModal.close()
			},
			// 改变事件
			onChange(e) {
				this.$emit("onChange", e.show)
			},
			// 切换选择项
			handleChange(id) {
				this.selectNumber = id
			},
			// 确认选择
			onConfirm() {
				this.$emit("confirm", this.selectNumber)
				this.onClose()
			},
		},
	}
</script>

<style lang="scss">
	.component-modal-drivers-number {
		position: relative;
		z-index: 999;

		.popup-box {
			background: #FFFFFF;
			border-radius: 40rpx 40rpx 0 0;
			padding: 48rpx 48rpx 0;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);

			.popup-header {
				display: flex;
				align-items: center;

				.title {
					color: #242629;
					font-size: 32rpx;
					font-weight: 600;
					line-height: 44rpx;
					flex: 1;
				}

				.close {
					width: 48rpx;
					height: 48rpx;
				}
			}

			.popup-content {
				min-height: 300rpx;

				.content-tips {
					color: #8D929C;
					font-size: 28rpx;
					font-weight: 600;
					line-height: 40rpx;
					margin-top: 16rpx;
				}

				.content-list {
					.list-item {
						margin-top: 48rpx;
						padding: 32rpx 44rpx;
						border-radius: 32rpx;
						overflow: hidden;
						border: 1px solid #242629;
						width: 32%;
						margin-right: 2%;
						text-align: center;
						position: relative;
						z-index: 1;

						.item-background {
							background: #FFF;
							position: absolute;
							top: 0;
							left: 0;
							right: 0;
							bottom: 0;
							z-index: -1;
						}

						.item-text {
							color: #242629;
							font-size: 32rpx;
							font-weight: 600;
							line-height: 44rpx;
						}

						&:nth-child(3n) {
							margin-right: 0;
						}

						&.active {
							border-color: var(--theme-color);

							.item-background {
								background: var(--theme-color);
								opacity: .05;
							}

							.item-text {
								color: var(--theme-color);
							}
						}
					}
				}
			}

			.popup-btn {
				margin-top: 32rpx;
				display: flex;
				justify-content: space-between;
				border-top: 1rpx solid #F6F7FB;
				padding: 16rpx 32rpx;

				.btn {
					width: 100%;
					color: #FFF;
					text-align: center;
					font-size: 28rpx;
					font-weight: 600;
					line-height: 40rpx;
					background: var(--theme-color);
					border-radius: 48rpx;
					padding: 28rpx 32rpx;
				}
			}
		}
	}
</style>